package com.ilarele.shopping.client.adaptors;

import java.util.ArrayList;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.ilarele.shopping.ProductComment;
import com.ilarele.shopping.client.R;

public class A1CommentsAdapter extends ArrayAdapter<ProductComment> {
	private final LayoutInflater mLayoutInflater;

	public A1CommentsAdapter(Activity activity, ArrayList<ProductComment> items) {
		super(activity, R.layout.a1_comment_item, items);
		mLayoutInflater = LayoutInflater.from(activity);
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		ViewHolder holder;

		if (view == null) {
			view = mLayoutInflater.inflate(R.layout.a1_comment_item, parent,
					false);

			holder = new ViewHolder();
			holder.name = (TextView) view.findViewById(R.id.comment_name);
			holder.content = (TextView) view.findViewById(R.id.comment_content);
			holder.date = (TextView) view.findViewById(R.id.comment_date);

			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}

		ProductComment item = getItem(position);
		holder.name.setText(item.senderName);
		holder.content.setText(item.content);
		holder.date.setText(item.date);
		return view;
	}

	private static class ViewHolder {
		TextView name;
		TextView date;
		TextView content;
	}
}
